<template>
  <div>
    <a-card class="contentFullHeight"  :bodyStyle="{padding : '10px 10px'}">
      <div class="">
        <a-card :bordered="true" class="searchBox" :bodyStyle="{padding : '10px 24px'}">
          <a-form layout="inline">

            <!--<a-form-item label="操作账号">-->
              <!--<a-select v-model="searchParams.sb" allowClear >-->
                <!--<a-select-option value="0">全部</a-select-option>-->
                <!--<a-select-option value="1">admin</a-select-option>-->
                <!--<a-select-option value="2">by11</a-select-option>-->
                <!--<a-select-option value="3">by11che11</a-select-option>-->
              <!--</a-select>-->
            <!--</a-form-item>-->

            <!--<a-form-item label="操作类型">-->
              <!--<a-select v-model="searchParams.type" allowClear>-->
                <!--<a-select-option value="0">全部</a-select-option>-->
                <!--<a-select-option value="1">新增</a-select-option>-->
                <!--<a-select-option value="2">修改</a-select-option>-->
                <!--<a-select-option value="3">删除</a-select-option>-->
              <!--</a-select>-->
            <!--</a-form-item>-->

            <a-form-item label="操作时间">
              <a-range-picker
                :defaultValue="[$util.moment(searchParams.bgTm),$util.moment(searchParams.endTm)]"
                :format="$defaultSettings.dateFormat"
                @change="onChange"/>
            </a-form-item>

            <a-form-item>
              <a-button type="primary" icon="search" @click="handleSearch">查询</a-button>
            </a-form-item>

          </a-form>
        </a-card>
      </div>

      <a-table :columns="columns" :dataSource="data"

               bordered size="small" rowKey="id"
               :pagination="pagination" :loading="loading"
               @change="handleTableChange"
      >
        <template slot="status" slot-scope="text,record">
          {{text | filter_status}}
        </template>
      </a-table>
    </a-card>


  </div>
</template>

<script>

  import {
    getUserOperationLogLogList
  } from "@/api/system/log"
  import moment from 'moment';
  export default {
    components: {},
    data() {
      return {
        /*   -------时间格式--------*/
        dateFormat: 'YYYY-MM-DD',
        /*   -------搜索框--------*/
        searchParams: {
//          code: '',
//          sb: '0',
//          gz:'0',
//          xh:'0',
          type:'0',
          bgTm: moment(new Date()).subtract(6, 'days').format('YYYY-MM-DD'),
          endTm: this.$defaultSettings.endTm,
        },

        /*   -------分页--------*/
        pagination: this.$defaultSettings.pagination ,

        /*   -------表格--------*/
        loading: false,
        columns:[
          {
            title: '用户名',
            dataIndex: 'createBy',
          },
          {
            title: '操作模块',
            dataIndex: 'operationModel'
          },
         {
          title: '操作内容',
          dataIndex: 'operationValue'
          },
          {
            title: '操作时间',
            dataIndex: 'createTime'
          },
        ],
        data:[]
      }
    },
    inject: ['upShow'],
    filters: {
      filter_status(status){
        const map = {
          200 : '成功' ,
          500 : '失败' ,
        }
        return map[status]
      }
    },
    created() {

    },
    mounted() {
      this.getTableData()
    },
    methods: {
      onChange(dates, dateStrings) {
        this.searchParams.bgTm = dateStrings[0];
        this.searchParams.endTm = dateStrings[1];
      },
      handleTableChange(pagination, filters, sorter) {
        this.pagination = pagination
        let sortOrder = ''
        let sortField = sorter.field ? sorter.field : ''
        if (sorter.order) {
          sortOrder = sortOrder === 'ascend' ? 'asc' : 'desc'
        }
        this.getTableData(sortField, sortOrder)
      },

      getTableData(sortField, sortOrder) {
        this.loading = true
        const parameter = {
          _search: true,//是否分页查询
          pageSize: this.pagination.pageSize || 10,
          pageNumber: this.pagination.current || 1,
          sortField: sortField || '',
          sortOrder: sortOrder || '',
          bgTm: this.searchParams.bgTm,
          endTm:this.searchParams.endTm,
        }
        getUserOperationLogLogList(parameter).then(res => {
          this.loading = false
          this.pagination.total = res.data.total
          this.data = res.data.records
        }).
        catch(err => {
          this.loading = false
        })
      },
      handleSearch() {
        this.pagination.current = 1
        this.getTableData()
      }
    }
  }
</script>

<style scoped>

</style>
